package com.wondersgroup.fjzlpt.tbxt.controller.rest.zh;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.quick.framework.util.QuickPrincipalUtils;
import com.wondersgroup.fjzlpt.tbxt.beans.req.zhYb.QueryOneReqBean;
import com.wondersgroup.fjzlpt.tbxt.beans.req.zhYb.SaveReqBean;
import com.wondersgroup.fjzlpt.tbxt.beans.resp.BaseRespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.wondersgroup.fjzlpt.tbxt.service.inter.zh.ZhYbService;

/**
 * 综合月报
 */
@RestController
@RequestMapping("/zhyb")
@Api(value = "综合月报标准接口", tags = "ZhYbRestController", description = "综合月报API")
public class ZhYbRestController {

    @Autowired
    private ZhYbService zhYbService;

    /**
     * 保存或修改
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "保存或修改", notes = "保存或修改综合月报", response = BaseRespBean.class)
    @RequestMapping(value = "save", method = RequestMethod.POST)
    public JSONObject save(HttpServletRequest request, SaveReqBean saveReqBean) {
        Map map = RequestUtils.GetParameterMap(request);
        map.put("YLJGID", QuickPrincipalUtils.getPtjgID(request));
        map.put("JGMC", (String) QuickPrincipalUtils.getUserinfoByKey(request, "YLJGMC"));
        map.put("JGLB", QuickPrincipalUtils.getJglbdm(request));
        map.put("XZQH", QuickPrincipalUtils.getXzqhdm(request));
        return zhYbService.save(map);
    }

    /**
     * 根据机构id和填报时间，查询某机构填报记录
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "查询", notes = "查询综合月报", response = QueryOneReqBean.class)
    @RequestMapping(value = "queryOne", method = RequestMethod.POST)
    public JSONObject queryOne(HttpServletRequest request,QueryOneReqBean queryOneReqBean) {
        Map<String, String> map = RequestUtils.GetParameterMap(request);
        if (StringUtils.isEmpty(map.get("YLJGID"))) {
            map.put("YLJGID", QuickPrincipalUtils.getPtjgID(request));
            map.put("JGMC", (String) QuickPrincipalUtils.getUserinfoByKey(request, "YLJGMC"));
        }
        return zhYbService.queryOne(map);
    }
}
